<?php
namespace Home\Controller;

use Think\Controller;
class FeedbackController extends CommonController {

   public static $feedback_title = '【 云途数据市场】用户留言';//用户留言邮件title
 
	/**
	* @desc 留言
	*/
    public function index(){
    	if(IS_POST){
            //条件判断
            $title = I('post.title','','strip_tags');
            $content = I('post.content','','strip_tags');
            $contact_way = I('post.contact_way',0,'intval');
            $contact_information = I('post.contact_information','','strip_tags');
            $contact_way_text = I('post.contact_way_text','','strip_tags');
            

            $data = array();
            if(empty($title) || empty($content) || empty($contact_information)){
                $return_data['msg'] = "数据不完整";
                $return_data['status'] = "1001";
                $return_data['data'] = "null";
                $this->ajaxReturn($return_data);
            }
            //数据入库 (后期需要加上防刷)
            $feedback = M('Feedback');
            $data['title'] = trim($title);
            $data['content'] = $content;
            $data['contact_way'] = $contact_way;
            $data['contact_information'] = trim($contact_information);
            $data['create_time'] = time(); 
            $result = $feedback->data($data)->add();
            
            //邮件（至王珂）
            if($result){
                //todo
                $email = "kew@37degree.com";
                $content = "";
                $content .= '<p>联系方式：'.$contact_way_text.' : '.trim($contact_information).'</p>';
                $content .= '<p>主题：'.trim($title).'</p>';
                $content .= '<p>内容：'.$content.'</p>';
                
                sendMail($email,self::$feedback_title,$content);
            }

            $return_data = array('msg'=>'已收到您的留言，我们会尽快给予答复!','status'=>200,'data'=>true);
            $this->ajaxReturn($return_data);
        }
        
    	//redis 测试
    	// if ( !extension_loaded('redis') ) {
     //        throw_exception(L('_NOT_SUPPERT_').':redis');
     //    }
     //    $redis = new \Redis();
    	// $result = $redis->connect( C(REDIS_HOST), C(REDIS_PORT) );
	   	// $redis->set("foor",'foor_123456');
	   	// echo $redis->get("foor");die;
	   //echo "Server is running: "+ $redis->ping();exit();
    	// $value = "1111111111111111";
	    // S('a',$value,300);
	    // echo S('a');exit();

    	//basic 授权测试
	    // $url = 'https://api.37degree.com/open/api_mgr_srv/user_add';
    	// echo "<pre>";print_r(dmp_curl_post($url) );exit;

    	//链接库
    	// $user = M('dmp_users');
    	// echo "<pre>";print_r($user);die;
    	// $test = M('Test','');
    	// echo "<pre>";print_r($test);die;

    	//发送email
    	//SendMail('704819236@qq.com','TEST','email-test');
    	// SendMail('tim_wutiyang@163.com','TEST','email-test');

    	//图片上传
    	//$this->display();
        // echo "BSS-Home/IndexController/index";
        // exit();
    }

}